<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>定级试卷模版</title>
     <link rel="stylesheet" href="../css/all.min.css">
    <style>
        body {
            font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
            font-size: 14px;
            line-height: 1.6;
            color: #333;
            margin: 0;
            padding: 20px;
            background-color: #fff;
        }
        
        .exam-container {
            max-width: 210mm;
            margin: 0 auto;
            background-color: #fff;
            padding: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-radius: 4px;
            position: relative;
        }
        
        .exam-header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #2d3748;
        }
        
        .exam-title {
            font-size: 24px;
            font-weight: 600;
            color: #1a365d;
            margin-bottom: 10px;
            letter-spacing: 1px;
        }
        
        .exam-subtitle {
            font-size: 16px;
            color: #4a5568;
            margin-bottom: 15px;
        }
        
        .exam-info {
            display: flex;
            justify-content: center;
            gap: 30px;
            font-size: 14px;
            color: #718096;
        }
        
        .candidate-info {
            margin-bottom: 30px;
        }
        
        .info-table {
            width: 100%;
            border-collapse: collapse;
        }
        
        .info-table th {
            padding: 12px 15px;
            border: 1px solid #2d3748;
            width: 15%;
            font-weight: 600;
            color: #2d3748;
        }

        .info-table td {
            padding: 12px 15px;
            border: 1px solid #2d3748;
        }
        
        .question-section {
            margin-bottom: 35px;
        }
        
        .section-title {
            font-size: 18px;
            font-weight: 600;
            color: #2b6cb0;
            margin-bottom: 15px;
            padding-bottom: 8px;
            border-bottom: 1px solid #bee3f8;
        }
        
        .section-subtitle {
            font-size: 15px;
            font-weight: 500;
            color: #4a5568;
            margin-bottom: 15px;
        }
        
        .choice-question {
            margin-bottom: 20px;
            page-break-inside: avoid;
        }
        
        .question-stem {
            margin-bottom: 10px;
            font-weight: 500;
            color: #2d3748;
        }
        
        .options {
            margin-left: 25px;
        }
        
        .option {
            margin-bottom: 8px;
        }
        
        .essay-question {
            margin-bottom: 30px;
            page-break-inside: avoid;
        }
        
        .question-content {
            margin-bottom: 15px;
            color: #4a5568;
        }
        
        .requirements {
            margin-left: 20px;
            margin-bottom: 15px;
        }
        
        .requirement {
            margin-bottom: 8px;
            position: relative;
            padding-left: 25px;
            color: #4a5568;
        }
        
        .requirement:before {
            content: "•";
            position: absolute;
            left: 5px;
            color: #4299e1;
            font-weight: bold;
        }
        
        .answer-area {
            min-height: 150px;
            padding: 15px;
            margin-top: 10px;
        }
        
        .fillblank-question {
            margin-bottom: 15px;
        }
        
        .blank {
            display: inline-block;
            min-width: 100px;
            border-bottom: 1px solid #2d3748;
            text-align: center;
            margin: 0 5px;
        }
        
        .judge-question {
            margin-bottom: 15px;
        }
        
        .action-buttons {
            position: fixed;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 10px;
            z-index: 100;
        }
        
        .action-btn {
            padding: 10px 20px;
            background: linear-gradient(135deg, #5a6ec2 0%, #683f8b 100%);
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .action-btn i {
            margin-right: 8px;
        }
        
        .action-btn:hover {
            background: linear-gradient(135deg, #683f8b 0%, #5a6ec2 100%);
        }
        
        .action-btn.fill-answers {
            background: linear-gradient(135deg, #683f8b 0%, #5a6ec2 100%);
        }
        
        .action-btn.fill-answers:hover {
            background: linear-gradient(135deg, #683f8b 0%, #5a6ec2 100%);
        }
        
        .reference-answer {
            color: #718096;
            font-style: italic;
            margin-top: 5px;
            display: none;
        }
        
        .show-answers .reference-answer {
            display: block;
        }
        
        .file-input {
            display: none;
        }
        
        .upload-label {
            padding: 10px 20px;
            background: linear-gradient(135deg, #683f8b 0%, #5a6ec2 100%);
            color: white;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            text-align: center;
            transition: background-color 0.3s;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .upload-label i {
            margin-right: 8px;
        }
        
        .upload-label:hover {
            background: linear-gradient(135deg, #5a6ec2 0%, #683f8b 100%);
        }
        
        .upload-container {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.4);
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            background-color: #fefefe;
            margin: auto;
            padding: 20px;
            border: 1px solid #888;
            border-radius: 8px;
            width: 300px;
            box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
            animation-name: animatetop;
            animation-duration: 0.3s;
            text-align: center;
        }
        
        @keyframes animatetop {
            from {top: -300px; opacity: 0}
            to {top: 0; opacity: 1}
        }
        
        .modal-close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        
        .modal-close:hover,
        .modal-close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
        
        .modal-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 10px;
            color: #1a365d;
        }
        
        .modal-message {
            margin-bottom: 20px;
        }
        
        .modal-button {
            padding: 8px 16px;
            background: linear-gradient(135deg, #5a6ec2 0%, #683f8b 100%);
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s;
        }
        
        .modal-button:hover {
            background: linear-gradient(135deg, #683f8b 0%, #5a6ec2 100%);
        }
        
        @media print {
            .action-buttons {
                display: none;
            }
            
            body {
                padding: 0;
                background-color: #fff;
            }
            
            .exam-container {
                box-shadow: none;
                margin: 0;
            }
            
            @page {
                size: A4;
                margin: 15mm 20mm;
            }
        }
    </style>
</head>
<body>
    <!-- 模态框 -->
    <div id="modal" class="modal">
        <div class="modal-content">
            <span class="modal-close">&times;</span>
            <div class="modal-title" id="modalTitle">提示</div>
            <div class="modal-message" id="modalMessage"></div>
            <button class="modal-button" id="modalButton">确定</button>
        </div>
    </div>

    <div class="action-buttons no-print">
        <button class="action-btn" onclick="exportTemplate()">
            <i class="fa fa-file"></i>试题模版
        </button>
        <div class="upload-container">
            <label class="upload-label" for="file-upload">
                <i class="fa fa-upload"></i>导入试卷
            </label>
            <input type="file" id="file-upload" class="file-input" accept=".json" onchange="handleFileUpload(event)">
        </div>
        <button class="action-btn" onclick="window.print()">
            <i class="fa fa-print"></i>打印试卷
        </button>
        <button class="action-btn fill-answers" onclick="toggleAnswers()">
            <i class="fa fa-eye"></i><span id="answerBtnText">显示答案</span>
        </button>
    </div>
    
    <div class="exam-container">
        <div class="exam-header">
            <div class="exam-title" contenteditable="true">专业技术能力评估考试</div>
            <div class="exam-subtitle" contenteditable="true">XX部门/XX岗位</div>
            <div class="exam-info">
                <span>考试时间：120分钟</span>
                <span>满分：100分</span>
            </div>
        </div>
        
        <div class="candidate-info">
            <table class="info-table">
                <tr>
                    <th>姓名</th>
                    <td></td>
                    <th>电话</th>
                    <td></td>
                </tr>
            </table>
        </div>

        <!-- 题目 -->
        <div id="questions-container"></div>
    </div>

    <script>
        // 试题数据
        let currentExamData = {};

        // 加载试题
        function loadQuestions(examData = currentExamData) {
            const container = document.getElementById('questions-container');
            container.innerHTML = ''; // 清空容器
            
            // 单选题部分
            if (examData.singleChoice && examData.singleChoice.questions.length > 0) {
                const singleChoiceSection = document.createElement('div');
                singleChoiceSection.className = 'question-section';
                singleChoiceSection.innerHTML = `<div class="section-title">${examData.singleChoice.title}</div>`;
                
                examData.singleChoice.questions.forEach(q => {
                    const optionsHtml = q.options.map(opt => `<div class="option">${opt}</div>`).join('');
                    singleChoiceSection.innerHTML += `
                        <div class="choice-question">
                            <div class="question-stem">${q.id}. ${q.stem}</div>
                            <div class="options">${optionsHtml}</div>
                            <div class="reference-answer">参考答案：${q.answer} &nbsp;|&nbsp; ${q.reference}</div>
                        </div>
                    `;
                });
                container.appendChild(singleChoiceSection);
            }
            
            // 多选题部分
            if (examData.multipleChoice && examData.multipleChoice.questions.length > 0) {
                const multipleChoiceSection = document.createElement('div');
                multipleChoiceSection.className = 'question-section';
                multipleChoiceSection.innerHTML = `<div class="section-title">${examData.multipleChoice.title}</div>`;
                
                examData.multipleChoice.questions.forEach(q => {
                    const optionsHtml = q.options.map(opt => `<div class="option">${opt}</div>`).join('');
                    multipleChoiceSection.innerHTML += `
                        <div class="choice-question">
                            <div class="question-stem">${q.id}. ${q.stem}</div>
                            <div class="options">${optionsHtml}</div>
                            <div class="reference-answer">参考答案：${q.answer} &nbsp;|&nbsp; ${q.reference}</div>
                        </div>
                    `;
                });
                container.appendChild(multipleChoiceSection);
            }
            
            // 填空题部分
            if (examData.fillInTheBlank && examData.fillInTheBlank.questions.length > 0) {
                const fillInTheBlankSection = document.createElement('div');
                fillInTheBlankSection.className = 'question-section';
                fillInTheBlankSection.innerHTML = `<div class="section-title">${examData.fillInTheBlank.title}</div>`;
                
                examData.fillInTheBlank.questions.forEach(q => {
                    const stemWithBlanks = q.stem.replace(/_______/g, '<span class="blank"></span>');
                    fillInTheBlankSection.innerHTML += `
                        <div class="fillblank-question">
                            <div class="question-stem">${q.id}. ${stemWithBlanks}</div>
                            <div class="reference-answer">参考答案：${q.answer} &nbsp;|&nbsp; ${q.reference}</div>
                        </div>
                    `;
                });
                container.appendChild(fillInTheBlankSection);
            }
            
            // 判断题部分
            if (examData.judge && examData.judge.questions.length > 0) {
                const judgeSection = document.createElement('div');
                judgeSection.className = 'question-section';
                judgeSection.innerHTML = `<div class="section-title">${examData.judge.title}</div>`;
                
                examData.judge.questions.forEach(q => {
                    judgeSection.innerHTML += `
                        <div class="judge-question">
                            <div class="question-stem">${q.id}. ${q.stem}</div>
                            <div class="reference-answer">参考答案：${q.answer} &nbsp;|&nbsp; ${q.reference}</div>
                        </div>
                    `;
                });
                container.appendChild(judgeSection);
            }
            
            // 简答题部分
            if (examData.shortAnswer && examData.shortAnswer.questions.length > 0) {
                const shortAnswerSection = document.createElement('div');
                shortAnswerSection.className = 'question-section';
                shortAnswerSection.innerHTML = `<div class="section-title">${examData.shortAnswer.title}</div>`;
                
                examData.shortAnswer.questions.forEach(q => {
                    shortAnswerSection.innerHTML += `
                        <div class="essay-question">
                            <div class="question-stem">${q.id}. ${q.stem}</div>
                            <div class="answer-area"></div>
                            <div class="reference-answer">参考答案：${q.reference}</div>
                        </div>
                    `;
                });
                container.appendChild(shortAnswerSection);
            }
            
            // 论述题部分
            if (examData.discussion && examData.discussion.questions.length > 0) {
                const discussionSection = document.createElement('div');
                discussionSection.className = 'question-section';
                discussionSection.innerHTML = `<div class="section-title">${examData.discussion.title}</div>`;
                
                examData.discussion.questions.forEach(q => {
                    discussionSection.innerHTML += `
                        <div class="essay-question">
                            <div class="question-stem">${q.id}. ${q.stem}</div>
                            <div class="answer-area"></div>
                            <div class="reference-answer">参考答案：${q.reference}</div>
                        </div>
                    `;
                });
                container.appendChild(discussionSection);
            }
        }
        
        // 显示/隐藏参考答案
        function toggleAnswers() {
            document.body.classList.toggle('show-answers');
            const btn = document.querySelector('.fill-answers');
            const btnText = document.getElementById('answerBtnText');
            if (document.body.classList.contains('show-answers')) {
                btnText.textContent = '隐藏答案';
                btn.innerHTML = '<i class="fa fa-eye-slash"></i><span id="answerBtnText">隐藏答案</span>';
            } else {
                btnText.textContent = '显示答案';
                btn.innerHTML = '<i class="fa fa-eye"></i><span id="answerBtnText">显示答案</span>';
            }
        }
        
        // 导出试卷模板
        function exportTemplate() {
            // 创建一个基本的试卷模板
            const template = {
                "singleChoice": {
                    "title": "一、单选题（每小题2分，共10题，满分20分）",
                    "questions": [
                        {
                            "id": 1,
                            "stem": "示例单选题：_______",
                            "options": [
                                "A. 选项1",
                                "B. 选项2",
                                "C. 选项3",
                                "D. 选项4"
                            ],
                            "answer": "A",
                            "reference": "示例单选题参考答案"
                        }
                    ]
                },
                "multipleChoice": {
                    "title": "二、多选题（每小题1分，共10题，满分10分）",
                    "questions": [
                        {
                            "id": 11,
                            "stem": "示例多选题：_______",
                            "options": [
                                "A. 选项1",
                                "B. 选项2",
                                "C. 选项3",
                                "D. 选项4"
                            ],
                            "answer": "ABCD",
                            "reference": "示例多选题参考答案"
                        }
                    ]
                },
                "fillInTheBlank": {
                    "title": "三、填空题（每小题1分，共10题，满分10分）",
                    "questions": [
                        {
                            "id": 21,
                            "stem": "示例填空题：_______",
                            "answer": "示例答案",
                            "reference": "示例填空题参考答案"
                        }
                    ]
                },
                "judge": {
                    "title": "四、判断题（每小题1分，共10题，满分10分）",
                    "questions": [
                        {
                            "id": 31,
                            "stem": "示例判断题：_______",
                            "answer": "√",
                            "reference": "示例判断题参考答案"
                        }
                    ]
                },
                "shortAnswer": {
                    "title": "五、简答题（每小题6分，共5题，满分30分）",
                    "questions": [
                        {
                            "id": 41,
                            "stem": "示例简答题：请简要说明云计算的三种服务模式。",
                            "reference": "示例简答题参考答案"
                        }
                    ]
                },
                "discussion": {
                    "title": "六、论述题（每小题10分，共2题，满分20分）",
                    "questions": [
                        {
                            "id": 46,
                            "stem": "示例论述题：论述企业数字化转型的关键要素和实施路径。",
                            "reference": "示例论述题参考答案"
                        }
                    ]
                }
            };
            
            // 将对象转换为JSON字符串
            const jsonContent = JSON.stringify(template, null, 2);
            
            // 创建Blob对象
            const blob = new Blob([jsonContent], {type: 'application/json'});
            
            // 创建下载链接
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'exam_template.json';
            
            // 触发下载
            document.body.appendChild(a);
            a.click();
            
            // 清理
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        }
        
        // 处理文件上传
        function handleFileUpload(event) {
            const file = event.target.files[0];
            if (!file) return;
            
            const reader = new FileReader();
            reader.onload = function(e) {
                try {
                    // 解析JSON内容
                    const uploadedData = JSON.parse(e.target.result);
                    
                    // 验证上传的数据格式
                    if (validateExamData(uploadedData)) {
                        // 更新当前考试数据并重新加载试题
                        currentExamData = uploadedData;
                        loadQuestions();
                        
                        // 清空文件输入，允许重复选择同一个文件
                        document.getElementById('file-upload').value = '';
                        
                        // 显示模态框提示
                        showModal('成功', '试卷导入成功！');
                    } else {
                        showModal('错误', '导入的JSON格式不正确，请检查。');
                    }
                } catch (error) {
                    console.error('解析JSON文件时出错:', error);
                    showModal('错误', '解析JSON文件时出错，请确保文件格式正确。');
                }
            };
            reader.readAsText(file);
        }
        
        // 验证导入的考试数据格式
        function validateExamData(data) {
            // 简单验证：检查是否包含必要的题型部分
            const requiredSections = ['singleChoice', 'multipleChoice', 'fillInTheBlank', 'judge', 'shortAnswer', 'discussion'];
            
            for (const section of requiredSections) {
                if (!data[section] || !data[section].questions || !Array.isArray(data[section].questions)) {
                    return false;
                }
            }
            
            return true;
        }
        
        // 显示模态框
        function showModal(title, message) {
            const modal = document.getElementById('modal');
            const modalTitle = document.getElementById('modalTitle');
            const modalMessage = document.getElementById('modalMessage');
            const modalButton = document.getElementById('modalButton');
            
            modalTitle.textContent = title;
            modalMessage.textContent = message;
            
            // 显示模态框
            modal.style.display = 'flex';
            
            // 点击按钮关闭模态框
            modalButton.onclick = function() {
                modal.style.display = 'none';
            };
            
            // 点击关闭图标关闭模态框
            document.querySelector('.modal-close').onclick = function() {
                modal.style.display = 'none';
            };
            
            // 点击模态框外部关闭
            modal.onclick = function(event) {
                if (event.target === modal) {
                    modal.style.display = 'none';
                }
            };
        }
        
        // 页面加载完成后初始化
        window.onload = function() {
            loadQuestions();
        };
    </script>
</body>
</html>